package com.conversationboard.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.conversationboard.model.NoSuchThreadException;
import com.conversationboard.model.Thread;

@WebServlet(name = "AdminMoveThreadToBoardControllerServlet", urlPatterns = "/Admin/AdminMoveThreadToBoardControllerServlet")
public class AdminMoveThreadToBoardControllerServlet extends HttpServlet {

	private static final long serialVersionUID = 4832091936889464283L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		int boardId = Integer.parseInt(request.getParameter("boardid"));
		int threadId = Integer.parseInt(request.getParameter("threadid"));

		try {

			Thread thread = Thread.get(boardId, threadId);

			request.setAttribute("threadtitle", thread.getTitle());
			request.setAttribute("boardid", boardId);
			request.setAttribute("threadid", threadId);

			RequestDispatcher dispatcher = request.getRequestDispatcher("/Pages/Admin/selectboard.jsp");
			dispatcher.forward(request, response);

		} catch (NoSuchThreadException e) {
			throw new ServletException(e);
		} catch (SQLException e) {
			throw new ServletException(e);
		}

	}

}
